package com.neusoft.yuejian_6.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.adapter.MyCollectActivityAdapter;
import com.neusoft.yuejian_6.javabean.Activity;
import com.neusoft.yuejian_6.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyCollectActivityActivity extends AppCompatActivity {
    private ImageView back;
    private int u_id;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collect_activity);
        initView();
        initEvents();
        initData();
    }

    private void initView(){

        back=(ImageView)findViewById(R.id.back);
        recyclerView=(RecyclerView) findViewById(R.id.my_collect);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局


    }
    private void initEvents() {

        //返回上一页
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


    }
    private void initData() {
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("user_id", 0);
          //   Log.d("we","u_id");

        UserModel userModel = new UserModel();
        //发送请求
        Call<List<Activity>> call = userModel.getMyCollectActivity
                (u_id,"3");
        //2.处理结果
        call.enqueue(new Callback<List<Activity>>() {
            @Override
            public void onResponse(Call<List<Activity>> call, Response<List<Activity>> response) {
                List<Activity> data = (List<Activity>) response.body();  //获取数据
                recyclerView.setAdapter(new MyCollectActivityAdapter(MyCollectActivityActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<Activity>> call, Throwable t) {

            }

        });

    }

}

